package thirdquestion;

public class cUserBiz implements UserBiz{
    private  User[] users;
    {
       User[] users={new User("admin","123456","张三","admin123.com"),
                new User("tom","123567","李四","tomcatcat.com")};

    }
    public cUserBiz(){
         /*User[] users={new User("admin",123456,"张三","admin123.com"),
                 new User("tom",123567,"李四","tomcatcat.com")};*/
    }
    /*public cUserBiz(User[] users) {
        this.users = users;
    }*/

    public void register(String username, String password, String rePassword, String name, String email) throws IllegalRegisterException {
        for (int i = 0; i <users.length ; i++) {
            if (users[i].getUsername().equals(username)){
                throw new IllegalRegisterException("信息错误：该用户名已经存在。。。");
            }
        }
        if (!password.equals(rePassword)){
            throw new IllegalRegisterException("信息错误：两次输入的密码不一致。。。");
        }
        System.out.println("注册成功");

    }

    public void login(String username, String password)  throws  IllegalLoginException{
        for (int i = 0; i <users.length ; i++) {
            if (!users[i].getUsername().equals(username)){
                throw new IllegalLoginException("信息错误：用户名不存在。。。");

            }else
            if ((users[i].getUsername().equals(username))&&(!users[i].getPassword().equals(password))){
               throw new IllegalLoginException("信息错误：用户名跟密码不匹配");
            }
        }
        System.out.println("登陆成功");

    }
}
